Skip to content

Conversation

@capccode
Copy link

@capccode capccode commented Apr 10, 2025

Description

This PR introduces a new API provider: "Custom OpenAI Compatible". This provider allows users to connect Roo to OpenAI-compatible APIs that have non-standard configurations, such as:

  • Custom authentication headers (e.g., YY-API-KEY instead of Authorization)
  • Custom or empty authentication header prefixes (e.g., no Bearer prefix)
  • URL structures where the model name is included in the path (e.g., /api/v1/chat/{model_name})

This enhances Roo's flexibility to integrate with a wider range of self-hosted LLM routers and third-party services.

This change supports the project roadmap goal of providing "More versatile 'OpenAI Compatible' support".

Changes

  • Added CustomOpenAiHandler in src/api/providers/custom-openai.ts to handle custom logic.
  • Updated src/api/index.ts to register the new provider.
  • Added new configuration options to src/schemas/index.ts.
  • Updated the settings UI (webview-ui/src/components/settings/ApiOptions.tsx) with fields for:
    • Custom Base URL
    • Custom API Key
    • Custom Auth Header Name (placeholder: Authorization)
    • Custom Auth Header Prefix (placeholder: Bearer , with tooltip)
    • Toggle for "Use model name in URL path"
    • Field for "Path Prefix" (appears when the toggle is enabled)
  • Added tests for the new provider logic in src/api/providers/__tests__/custom-openai.test.ts.
  • Set default model for this provider to claude-3-7-sonnet-20250219.

How to Test

  1. Build the extension (npm run build) or run in the Extension Development Host (F5).
  2. Go to Roo Settings -> API Provider.
  3. Select "Custom OpenAI Compatible".
  4. Configure the settings:
    • Enter a Base URL.
    • Enter an API Key.
    • Set "Auth Header Name" (e.g., YY-API-KEY).
    • Leave "Auth Header Prefix" empty (or set if needed).
    • Enable "Use model name in URL path".
    • Set "Path Prefix" (e.g., /api/v1/chat/).
    • Select a model.
  5. Attempt to send a message through Roo.
  6. Verify that the API request is sent to the correct URL (<base_url><path_prefix><model_name>) with the correct custom authentication header.

Screenshot

https://imgur.com/a/ZQrjvbE

Breaking Changes

None.


Important

Introduces Custom OpenAI Compatible API provider with custom authentication and URL configurations, updating handler logic, UI, and schemas.

  • Behavior:
    • Adds CustomOpenAiHandler in custom-openai.ts to handle custom authentication headers, URL structures, and model paths.
    • Registers custom-openai provider in index.ts.
    • Default model set to claude-3-7-sonnet-20250219.
  • UI:
    • Updates ApiOptions.tsx to include fields for custom base URL, API key, auth header name, and prefix.
    • Adds toggle for model name in URL path and path prefix field.
  • Tests:
    • Adds tests in custom-openai.test.ts for handler construction, error handling, and endpoint usage.
  • Schemas and Types:
    • Updates providerSettingsSchema in schemas/index.ts to include new fields for custom provider.
    • Adds custom-openai to providerNames and PROVIDERS in constants.ts.

This description was created by Ellipsis for ec18380. It will automatically update as commits are pushed.

… connect roo to openai compatible apis that have non standard configs

ustom auth headers instead of `authorization` custom or empty auth header prefixes and url
structures where model is included in the path
@changeset-bot
Copy link

changeset-bot bot commented Apr 10, 2025

⚠️ No Changeset found

Latest commit: e473d67

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Apr 10, 2025
console.error("Custom OpenAI API request failed:", error)
let errorMessage = "Custom OpenAI API request failed."
if (axios.isAxiosError(error) && error.response) {
errorMessage += ` Status: ${error.response.status}. Data: ${JSON.stringify(error.response.data)}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider refining error handling. Instead of yielding an error chunk with potential internal details (e.g. from JSON.stringify on error.response.data), it might be safer to throw an error or return a sanitized message so sensitive data isn’t inadvertently exposed.

Suggested change
errorMessage += ` Status: ${error.response.status}. Data: ${JSON.stringify(error.response.data)}`
errorMessage += ` Status: ${error.response.status}. Data: [REDACTED]`

onInput={handleInputChange("customBaseUrl")}
placeholder="https://your-custom-api.example.com"
className="w-full">
<label className="block font-medium mb-1">Custom Base URL</label>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User-facing strings for the custom-openai settings (e.g. 'Custom Base URL', 'Custom API Key', 'Auth Header Name', 'Auth Header Prefix') are hard-coded. For internationalization compliance, wrap these strings with the translation function t.

Suggested change
<label className="block font-medium mb-1">Custom Base URL</label>
<label className="block font-medium mb-1">{t('settings:customOpenAi.customBaseUrl')}</label>

@hannesrudolph hannesrudolph moved this from New to PR [Pre Approval Review] in Roo Code Roadmap Apr 10, 2025
@capccode capccode closed this Apr 10, 2025
@github-project-automation github-project-automation bot moved this from PR [Pre Approval Review] to Done in Roo Code Roadmap Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant